﻿using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infastruucture;
using BasicData.Read.API.application.Command.Role;
using MediatR;

namespace BasicData.Read.API.application.CommandHandler.Role
{
    public class FindRoleCommandHandler : IRequestHandler<FindRoleCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<UserRoleModel> userRoleRep;

        public FindRoleCommandHandler(IBaseRepository<UserRoleModel> UserRoleRep)
        {
            userRoleRep = UserRoleRep;
        }
        public Task<ApiResult<List<int>>> Handle(FindRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<int>> res = new ApiResult<List<int>>();
            var list = userRoleRep.GetAll().Where(x => x.UserId == request.UserId && x.IsDeleted == false).Select(o => o.RoleId);
            res.Code = BaseEnums.Success;
            res.Msg = "角色信息反填成功";
            res.Data = list.ToList();
            return Task.FromResult(res);
        }

    }
}
